<template>
  <div class="overview-style">
    <div class="top-select-group">
      <el-input placeholder="请输入字段名称" v-model="searchKeyword" clearable style="width: 216px"></el-input>
      <el-button type="primary">搜索</el-button>
      <el-button style="float:right;" type="primary" @click="addDialogVisible=true">添加字段</el-button>
    </div>
    <div class="bottom-table-group">
      <el-table
        :header-cell-style="{'background-color':'#e6f1ff','height':'62px'}"
        ref="multipleTable"
        :data="tableData"
        v-loading="isLoading"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column prop="realName" label="客户姓名" align="center"></el-table-column>
        <el-table-column prop="phone" label="客户电话" align="center"></el-table-column>
        <el-table-column prop="email" label="客户邮箱" align="center"></el-table-column>
        <el-table-column prop="company" label="客户公司" align="center"></el-table-column>
        <el-table-column prop="address" label="客户地址" align="center"></el-table-column>
        <el-table-column prop="level" label="客户等级" align="center"></el-table-column>
        <el-table-column prop="state" label="客户状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state=='在线'" style="color:#2ed477">{{scope.row.state}}</span>
            <span v-else style="color: #ff6262">{{scope.row.state}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button @click="addDialogVisible=true" type="text" size="normal">编辑</el-button>
            <el-button @click="deleteDialogVisible=true" type="text" size="normal">删除</el-button>
            <el-button type="text" size="normal">上移</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="bottom-pagination-group">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, prev, pager, next,sizes, jumper"
          :total="totalData"
        ></el-pagination>
      </div>
    </div>

    <el-dialog title="删除确认" :visible.sync="deleteDialogVisible" top="34vh" width="26%">
      <div class="delete-dialog-style">分组删除后无法恢复，确定删除此分组信息吗？</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="deleteDialogVisible = false">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="添加客户字段" top="9vh" :visible.sync="addDialogVisible" width="33%">
      <div class="add-dialog-style">
        <el-form ref="addOrderForm" :model="addOrderForm" label-position="left" label-width="120px">
          <el-form-item :rules="{ required: true, message: '请输入'}" label="字段名称">
            <el-input style="width:100%;" v-model="addOrderForm.name1" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="是否必填">
            <el-radio-group v-model="addOrderForm.name2">
              <el-radio label="是"></el-radio>
              <el-radio label="否"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="文本类型">
            <el-radio-group v-model="addOrderForm.name3">
              <el-radio label="单行文本"></el-radio>
              <el-radio label="多行文本"></el-radio>
              <el-radio label="时间"></el-radio>
            </el-radio-group>
            <el-radio-group v-model="addOrderForm.name3">
              <el-radio label="日期"></el-radio>
              <el-radio label="数值"></el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native.prevent="handleClean" type="text" size="normal">清空</el-button>
        <el-button @click="addDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="addDialogVisible = false">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import api from "@/api/api";
export default {
  name: "SettingCustomerInfo",
  components: {},
  props: {},
  data() {
    return {
      tableData: [],
      deleteDialogVisible: false,
      addDialogVisible: false,
      addOrderForm: {},
      currentPage: 1,
      pageSize: 10,
      totalData: 0,
      isLoading: false
    };
  },
  watch: {},
  computed: {},
  methods: {
    handleSizeChange(size) {
      this.pageSize = size;
      this.getPageData();
    },
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getPageData();
    },
    getPageData() {
      this.isLoading = true;
      api
        .getAllCustomerAPI({
          page: this.currentPage,
          limit: this.pageSize
        })
        .then(res => {
          this.isLoading = false;
          let { error, data } = res.data;
          if (error) {
            this.$message.error("请求接口异常");
          } else {
            this.totalData = data.total;
            this.tableData = data.page;
          }
        });
    }
  },
  created() {
    this.getPageData();
  },
  mounted() {}
};
</script>

<style scoped>
.overview-style {
  padding: 20px;
  background-color: #fff;
  border-radius: 5px;
}
.bottom-pagination-group {
  padding: 20px 20px 0;
  float: right;
}
.bottom-table-group {
  margin-top: 20px;
  display: inline-block;
  width: 100%;
}
.add-dialog-style {
  height: 220px;
  overflow: auto;
  padding: 20px 0 10px 20px;
  margin-top: 10px;
  border-top: 1px solid #f2f2f2;
  border-bottom: 1px solid #f2f2f2;
}
.delete-dialog-style {
  border-top: 1px solid #f2f2f2;
  border-bottom: 1px solid #f2f2f2;
  padding: 20px;
  padding-bottom: 70px;
}
</style>
